<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">
        {{date | formatDate | reverseText(' ')}}
    </div>
    <script>
        let vm = new Vue({
            el:"#app",
            data:{
                date:"",
                closeTimer:null,
            },
            filters:{
                // 自定义时间
                formatDate(value){
                let oDate = new Date(value)
                let year = oDate.getFullYear()
                let month = oDate.getMonth() + 1
                let day = oDate.getDate() 
                let hours = oDate.getHours() 
                let minutes = oDate.getMinutes() 
                let seconds = oDate.getSeconds() 
                return year + '-' + month + '-' + day +' '+hours+':'+minutes+':'+seconds
                },
                // 倒叙
                reverseText(value,str){
                     return value.split(str).reverse().join(str)
                },
            },
            mounted(){
                this.date = new Date()
                this.closeTimer = setInterval(()=>{
                    this.date = new Date()
                },1000)
            },
            // 清除计时函数啥
            beforeDestroy(){
                if(this.closeTimer){
                    clearInterval(this.closeTimer)
                }
            }
        })
    </script>
</body>
</html>